<template>
    <div align='center'>
        <table border="1" cellspacing='0' width='80%'>
            <tr align='center'>
                <th>用户名</th>
                <th>密&emsp;码</th>
                <th>权&emsp;限</th>
                <th>修改权限</th>
            </tr>
            <tr v-for="item in user" :key="item.id" align='center'>
                <th>{{item.username}}</th>
                <th>{{item.password}}</th>
                <th>{{item.level}}</th>
                <th><a-button type='primary' @click="put">修改权限</a-button></th>
            </tr>
        </table>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            user:[],
        }
    },
    methods: {
        get_user(){
            axios({
                url:'http://127.0.0.1:8000/access/',
                method:'get',
            }).then(resp=>{
                console.log(resp.data)
                this.user = resp.data
            })
        },
        put(){
            var level = prompt('权限',this.level)
                axios({
                    url:'http://127.0.0.1:8000/access/',
                    method:'put',
                    params:{
                        uid:localStorage.getItem('uid')
                    },
                    data:{
                        level:level
                    }
                }).then(resp=>{
                    console.log(resp.data)
                    alert(resp.data.msg)
                    this.$router.go(0)
                }) 
            }
    },
    created() {
        this.get_user()
    }
}
</script>

<style scoped>

</style>